package de.koller.oceanFramework.util;

import java.util.*;

public class OceanSet<T> implements Iterable<T> {
	
	private final Set<T> set = new HashSet<>();
	private final List<T> add = new ArrayList<>();
	private final List<T> del = new ArrayList<>();
	
	@Override
	public Iterator<T> iterator() {
		return set.iterator();
	}
	
	/** Call if, and only if, every iterator is unused! */
	public void update() {
		set.addAll( add );
		set.removeAll( del );

		add.clear();
		del.clear();
	}
	
	public void add( T element ) {
		add.add( element );
	}
	
	public void remove( T element ) {
		del.add( element );
	}
	
	public void addAllTo( Collection<? super T> collection ) {
		for( T e : this )
			collection.add( e );
	}

	public boolean isEmpty() {
		return set.isEmpty();
	}
	
}
